package com.gitee.slowcreator.http.config;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zxw
 * @date 2023/1/8 下午12:33
 */
public class HttpContextManager {

    private static final ThreadLocal<Map<String, Object>> context = ThreadLocal.withInitial(ConcurrentHashMap::new);

    public static void add(String key, Object value) {

        Map<String, Object> map = context.get();
        map.put(key, value);
    }

    public static void addMap(Map<String, Object> params) {

        Map<String, Object> map = context.get();
        map.putAll(params);
    }

    public static Object get(String key) {

        Map<String, Object> map = context.get();
        return map.get(key);
    }

    public static Object get() {

        return context.get();
    }

    public static void remove() {

        context.remove();
    }
}
